package controllers;

import com.fasterxml.jackson.databind.JsonNode;
import dao.BillInfo_Repository;
import play.data.FormFactory;
import play.libs.Json;
import play.libs.concurrent.HttpExecutionContext;
import play.mvc.Controller;
import play.mvc.Result;

import javax.inject.Inject;
import java.util.concurrent.CompletionStage;

public class BillInfoController extends Controller{

    private final FormFactory formFactory;
    private final BillInfo_Repository tBillInfoRepository;
    private final HttpExecutionContext ec;

    @Inject
    public BillInfoController(FormFactory formFactory, BillInfo_Repository tBillInfoRepository, HttpExecutionContext ec) {
        this.formFactory = formFactory;
        this.tBillInfoRepository = tBillInfoRepository;
        this.ec = ec;
    }

    public CompletionStage<Result> getBillInfoList() {
        JsonNode json = request().body().asJson();
//        String BillNo = json.findPath("BillNo").textValue();
        String status =json.findPath("status").textValue();
        String PhoneNumber = json.findPath("PhoneNumber").textValue();
        String StartDate = json.findPath("StartDate").textValue();
        String EndDate = json.findPath("EndDate").textValue();
        String HWMC = json.findPath("HWMC").textValue();
        String KHMC = json.findPath("KHMC").textValue();
        String Status = json.findPath("Status").textValue();


        return tBillInfoRepository.getBillInfoList(status,PhoneNumber, StartDate, EndDate, HWMC, KHMC, Status).thenApplyAsync(_tBillInfoRepository -> {
            return ok(Json.toJson(_tBillInfoRepository));
        }, ec.current());
    }

}
